/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tbenglish_bll;

import bllInterface.BLLFactory;
import bllfactory.*;
import dalInterface.*;
import dalfactory.SDALFactory;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import utils.DefaultPort;

/**
 *
 * @author salm
 */
public class TBEnglish_BLL
{
    private static String DALHost;
    private static String BLLHost;
    
    private static void readHost()
    {
        // NEED TABLE
        try
        {
            Properties p = new Properties();
            p.load(new FileInputStream("src\\RMIConfig.ini"));
            
            DALHost = p.getProperty("DALHost");
            BLLHost = p.getProperty("BLLHost");
        }
        catch (IOException ioEx)
        {
            DALHost = "rmi://localhost";
            BLLHost = "rmi://localhost";
        }
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            readHost();
            DALFactory dalFact = (DALFactory) Naming.lookup(String.format("%s:%d/%s", DALHost, DefaultPort.getInstance().getDALPort(), "DALFactory"));
            SDALFactory.initInstance(dalFact);
            
            LocateRegistry.createRegistry(DefaultPort.getInstance().getBLLPort());
            BLLFactory bllFact = new BLLFactoryImpl();
            BLLFactory bllFactExported = (BLLFactory) UnicastRemoteObject.exportObject(bllFact, DefaultPort.getInstance().getBLLPort());
            Naming.rebind(String.format("%s:%d/%s", BLLHost, DefaultPort.getInstance().getBLLPort(), "BLLFactory"), bllFactExported);
        } catch (RemoteException | NotBoundException | MalformedURLException ex) {
            Logger.getLogger(TBEnglish_BLL.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}